/**
 * @author zhouyi
 * @version 1.0.0
 * @requires jquery-1.2.6.js
 */
(function($){
	/*****************************************初始对象*****************************************/
	$.youi = $.youi || {};//$.youi 对象
	/*****************************************服务配置*****************************************/
	$.youi.serverConfig={
		path : '',//当前服务器路径 例如：http://127.0.0.1:8090/youi/,
		notPassedProperties:[],//不显示的字段数组，根据当前访问的页面路径由服务器生成
		convertArray:[]//数据字典数组，服务器生成
	};
	/*****************************************数据类型*****************************************/
	$.youi.dataType = {
		'string'	:'string',
		'int'		:'int',
		'float'		:'float',
		'date'		:'date',
		'boolean'	:'boolean'
	};
	
	$.youi.connectKeyValue = function(key,value){
		var keyValue='';
		if(key&&value){
			keyValue = '&'+key+'='+value;
		}
		return keyValue;
	};
	/*****************************************时间记录*****************************************/
	$.youi.time = {
		startTimes:[],
		
		start:function(){
			this.startTimes.push(new Date().getTime());
		},
		
		end:function(message){
			message = (message+'耗时：')||'';
			var startTime = this.startTimes.pop();
			if(startTime){
				var endTime = new Date().getTime();
				$.youi.log.info(message+(endTime-startTime)+'ms');
			}
		}
	};
	/*****************************************解析数据*****************************************/
	$.youi.parseDatas = function(result,srcType){
		var datas;
		switch(srcType){
			case  'json':
				datas = result;
				break;
			case  'xml'://未实现
				break;
		}
		return datas;
	};
	/*****************************************判断属性显示***************************************/
	$.youi.propertyPassed = function(property){
		var passed = true;
		$.each($.youi.serverConfig.notPassedProperties,function(){
			if(property==this){
				passed = false;
			}
		});
		return passed;
	};
	/*****************************************mock列表数据*************************************/
	$.youi.mockRecords = function(o){
		$.youi.time.start();
		o = $.extend({
			prifex:'',
			beginIndex:0,
			size:200
		},o);//参数将覆盖默认值
		
		var records = [];
		var properties = o.properties;
		
		var property;
		var value;
		for(var i=0;i<o.size;i++){
			var record = {};
			for(var j=0;j<properties.length;j++){
				property = properties[j];
				if(property.dataType=='int'){
					value = o.beginIndex+i;
				}if(property.dataType=='boolean'){
					value = true;
				}else{
					value = o.prifex+property.property+'-'+(o.beginIndex+i);
				}
				record[property.property]=value;
				
				property = null;
				value = null;
			}
			records.push(record);
		}
		$.youi.time.end('模拟'+o.size+'条数据');
		return records;
	};
	
	/*****************************************数据对象*****************************************/
	$.youi.record = function(o){
		if(o!==null){
			for(var property in o){
				if(typeof(o[property])!='function'){
					this.setValue(property,o[property]);
				}
			}
		}
	};
	
	$.youi.record.prototype = {
		setValue:function(name,value){
			this[name] = value;
		},
		
		getValue:function(name){
			return this[name];
		},
		
		removeValue:function(name){
			delete this[name];
		},
		
		toString:function(){
			var sArray = [];
			for(var property in this){
				if(typeof(this[property])!='function'){
					sArray.push(',');
					sArray.push(property);
					sArray.push('=');
					sArray.push(this[property]);
				}
			}
			return sArray.join('');
		}
	};
})(jQuery);

/**********************************************输出日记信息**************************************/
(function (jQuery){
    this.info = function(message) {
        var outPanel = getOutPanel();
        var aDate = new Date();
        var time = aDate.getFullYear()+'-'+(aDate.getMonth()+1)+'-'+aDate.getDate()+' '+aDate.getHours()+':'+aDate.getMinutes();//+':'+aDate.getSeconds();
        outPanel.prepend('[info]'+time+' '+message+'<br>');
        return jQuery;
	};
	   
    this.clear = function(name) {   
        var outPanel = getOutPanel();
        outPanel.empty();
        return jQuery;
	};
	
	function getOutPanel(){
		var outPanel = $('#youi-out');
		if(outPanel.length==0){
			outPanel = $('<div class="youi-out" id="youi-out"/>');
			$('body',document).append(outPanel);
		}
		return outPanel;
	};
	
    jQuery.youi.log = this;
    return jQuery;    
})(jQuery);